
const app = getApp()
Page({
  data: {
    currentId:0,
    userInfo:{},
    notice:{},
    rules_list:[],
    systemOs: app.globalData.systemOs
  },
  onLoad: function (options) {
    this.setData({
      userInfo:app.userinfo
    })
    this.getMemberRules()
  },
  getMemberRules(){
    let _this = this
    app.util.request({
      url: 'api/feedback/findall',
      method: "post",
      data: {
        page:1,
        pageSize:10,
      },
      success(response) {
          if (response.data.code == 0) {
            _this.setData({
              rules_list:response.data.data[0].feedback,
              notice:response.data.data[0].norice,
            })
          }
      }
    })
  },
  chooseFeedback(e){
    this.setData({
      currentId: e.currentTarget.dataset.id
    })
  },
  toAddMember(){
    let _this = this
    
    app.util.request({
      url: 'api/member/add',
      method: "post",
      data: {
        feedbackId:this.data.currentId
      },
      success(response) {
          if (response.data.code == 0) {
            _this.payorder(response.data.data)
          } else {
            wx.showToast({
              icon: 'none',
              title: response.data.msg,
            })
          }
      }
    })
  },
	payorder(outTradeNo) {
		let _this = this;
		_this.setData({
			loading: true
		})
		let data = {
			outTradeNo: outTradeNo
		};
		app.util.request({
			url: "wxPay/miniAppPay",
			data: data,
			method: "get",
			success(response) {
				let data = response.data.data;
				wx.requestPayment({
					timeStamp: data.timeStamp,
					nonceStr: data.nonceStr,
					package: data.package,
					signType: data.signType,
					paySign: data.paySign,
					appId: data.appId,
					success(res) {
						if (res.errMsg == "requestPayment:ok") {
							wx.showToast({
								title: '支付成功！',
							})
							_this.setData({
								hasPay: true
							})
						}
					},
					fail(res) {
						console.log(res)
						_this.setData({
							hasPay: false
						})
					}
				})
			},
			complete() {
				_this.setData({
					loading: false
				})
			}
		})
	},
})
